package com.project.common.utils.collection;

import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 集合工具类
 *
 * @Author: 汪焰
 * @Date: 2020/6/7 22:22
 * version 1.0.0
 **/
public class CollectionsUtils extends CollectionUtils {

	public static boolean isBlank(List<?> obj) {
		return null == obj || obj.isEmpty();
	}

	public static boolean isNotBlank(List<?> obj) {
		return null != obj && !obj.isEmpty();
	}

	public static boolean isBlank(Collection<?> obj) {
		return null == obj || obj.isEmpty();
	}

	public static boolean isNotBlank(Collection<?> obj) {
		return null != obj && !obj.isEmpty();
	}

	public static List<Object> convert(Collection<?> obj) {
		if (isBlank(obj)) {
			return null;
		}
		return new ArrayList<>(obj);
	}

	public static List<Long> convert(Long[] values) {
		List<Long> result = new ArrayList<>(values.length);
		Collections.addAll(result, values);
		return result;
	}

	public static List<Integer> convert(Integer[] values) {
		List<Integer> result = new ArrayList<>(values.length);
		Collections.addAll(result, values);
		return result;
	}

	public static List<Double> convert(Double[] values) {
		List<Double> result = new ArrayList<>(values.length);
		Collections.addAll(result, values);
		return result;
	}

	public static List<String> convert(String[] values) {
		List<String> result = new ArrayList<>(values.length);
		Collections.addAll(result, values);
		return result;
	}

	public static void clear(List<?> obj) {
		if (isNotBlank(obj)) {
			obj.clear();
		}
	}

	public static void clear(Collection<?> obj) {
		if (isNotBlank(obj)) {
			obj.clear();
		}
	}
}
